package main.service;
import main.repository.*;


import java.util.*;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import main.entity.*;
import main.vo.*;

@Service
public class TianjiadqyhfjxxUserService {

//系统生成代码,请不要修改或删除 <actionStart:zhucexx>
	public String zhucexx(String sys_XCredentialUserId) throws Exception{
        //当前函数的代码为自动生成,请勿手动修改!!!
        java.util.List < Yonghufjxx > userEXinfo = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).queryEntityByFyonghuidEquals(sys_XCredentialUserId);
        if ((com.justep.util.ListUtil.isEmpty(userEXinfo))) {
            String info = "新用户";
            return "新用户";
        } else {
            return "老用户";
        }

    }
//系统生成代码,请不要修改或删除 <actionEnd:zhucexx>

//系统生成代码,请不要修改或删除 <actionEnd:zhucexx>	


//系统生成代码,请不要修改或删除 <actionStart:zhuceyhltlb>
public String zhuceyhltlb(String sys_XCredentialUserId, String user2ID) throws Exception{
        //当前函数的代码为自动生成,请勿手动修改!!!
        java.util.List < Yonghufjxx > ThisUserInfo = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).queryEntityByFyonghuidEquals(sys_XCredentialUserId);
        java.util.List < Yonghufjxx > AnotherUserInfo = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).queryEntityByFyonghuidEquals(user2ID);
        if ((com.justep.util.ListUtil.isEmpty(ThisUserInfo))) {
            return "补充信息";
        } else {
            if ((com.justep.util.ListUtil.isEmpty(AnotherUserInfo))) {
                return "对象无效";
            } else {
                java.util.List < Liaotianlb > chatLIstFilt1 = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.LiaotianlbRepository.class).queryEntityByFyonghu2EqualsAndFyonghu1Equals(user2ID, sys_XCredentialUserId);
                if ((com.justep.util.ListUtil.isEmpty(chatLIstFilt1))) {
                    java.util.List < Liaotianlb > chatListFilt2 = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.LiaotianlbRepository.class).queryEntityByFyonghu2EqualsAndFyonghu1Equals(sys_XCredentialUserId, user2ID);
                    if ((com.justep.util.ListUtil.isEmpty(chatListFilt2))) {
                        Liaotianlb currrentList = new Liaotianlb();
                        currrentList.setFyonghu1(sys_XCredentialUserId);
                        currrentList.setFyonghu2(user2ID);
                        currrentList.setFzuihouytxxdjssj(com.justep.util.DateTimeUtil.now());
                        Liaotianlb currentList_final = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.LiaotianlbRepository.class).saveAndFlush(currrentList);
                        return currentList_final.getFid();
                    } else {
                        Liaotianlb currentList = com.justep.util.ListUtil.getFirst(chatListFilt2);
                        return currentList.getFid();
                    }
                } else {
                    Liaotianlb currentList = com.justep.util.ListUtil.getFirst(chatLIstFilt1);
                    return currentList.getFid();
                }
            }
        }

    }
//系统生成代码,请不要修改或删除 <actionEnd:zhuceyhltlb>
	


//系统生成代码,请不要修改或删除 <actionStart:jiarugwj>
public String jiarugwj(String sys_XCredentialUserId, String spID, Integer num, Integer select) throws Exception{
        //当前函数的代码为自动生成,请勿手动修改!!!
        java.util.List < Gouwuj > rows = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.GouwujRepository.class).queryEntityByFshangpinidEqualsAndFyonghuEquals(spID, sys_XCredentialUserId);
        if ((com.justep.util.ListUtil.isEmpty(rows))) {
            Gouwuj newCart = new Gouwuj();
            newCart.setFshangpinid(spID);
            newCart.setFshuoliang(1);
            newCart.setFyonghu(sys_XCredentialUserId);
            newCart.setFxuanzhong(select);
            com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.GouwujRepository.class).saveAndFlush(newCart);
            return "收藏成功";
        } else {
            Gouwuj cartItem = com.justep.util.ListUtil.getFirst(rows);
            cartItem.setFxuanzhong(select);
            com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.GouwujRepository.class).saveAndFlush(cartItem);
            return "已收藏";
        }

    }
//系统生成代码,请不要修改或删除 <actionEnd:jiarugwj>

	


//系统生成代码,请不要修改或删除 <actionStart:fasongltnr>
public String fasongltnr(String tableID, String content, String sys_XCredentialUserId) throws Exception{
        //当前函数的代码为自动生成,请勿手动修改!!!
        if ((org.apache.commons.lang.StringUtils.isBlank(content))) {
            String
            var = tableID;
            return "不能发送空内容";
        } else {
            Liaotianjl chat = new Liaotianjl();
            chat.setFxiaoxinr(content);
            chat.setFfasongfid(sys_XCredentialUserId);
            chat.setFfasongsj(com.justep.util.DateTimeUtil.now());
            chat.setFliaotianlbid(tableID);
            com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.LiaotianjlRepository.class).saveAndFlush(chat);
            Liaotianlb chatTable = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.LiaotianlbRepository.class).findOne(tableID);
            chatTable.setFzuihouytxxdnr(content);
            chatTable.setFzuihouytxxdjssj(com.justep.util.DateTimeUtil.now());
            com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.LiaotianlbRepository.class).saveAndFlush(chatTable);
            String sender = chatTable.getFyonghu1();
            String receiver = chatTable.getFyonghu2();
            if (!(chatTable.getFyonghu1().equals(sys_XCredentialUserId))) {
                sender = chatTable.getFyonghu2();
                receiver = chatTable.getFyonghu1();
            }
            java.util.List < Yonghufjxx > Sender = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).queryEntityByFyonghuidEquals(sender);
            Yonghufjxx senderInfo = com.justep.util.ListUtil.getFirst(Sender);
            java.util.List < Yonghufjxx > Receiver = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).queryEntityByFyonghuidEquals(receiver);
            Yonghufjxx receiverInfo = com.justep.util.ListUtil.getFirst(Receiver);
            senderInfo.setFzuihouycfwltlbdsj(com.justep.util.DateTimeUtil.now());
            senderInfo.setFshoudaozhytxxdsj(com.justep.util.DateTimeUtil.now());
            receiverInfo.setFshoudaozhytxxdsj(com.justep.util.DateTimeUtil.now());
            com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).saveAndFlush(senderInfo);
            com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).saveAndFlush(receiverInfo);
            return content;
        }

    }
//系统生成代码,请不要修改或删除 <actionEnd:fasongltnr>


	





	





	





	





	





	





	





	


//系统生成代码,请不要修改或删除 <actionStart:chuangjiandd>
public String chuangjiandd(String spID, String buyerSaying, String sys_XCredentialUserId) throws Exception{
        //当前函数的代码为自动生成,请勿手动修改!!!
        Shangpin1 shangpin = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.Shangpin1Repository.class).findOne(spID);
        Integer num = shangpin.getFkucun();
        if ((num <= 0)) {
            return "卖光了";
        } else {
            Dingdan newOrder = new Dingdan();
            java.util.List < Yonghufjxx > usersys = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.YonghufjxxRepository.class).queryEntityByFyonghuidEquals(sys_XCredentialUserId);
            if (!(com.justep.util.ListUtil.isEmpty(usersys))) {
                Yonghufjxx buyer = com.justep.util.ListUtil.getFirst(usersys);
                if (!(org.apache.commons.lang.StringUtils.isBlank(buyer.getFsushem()))) {
                    newOrder.setFshouhuodz(buyer.getFsushem() + buyer.getFzuohao());
                    newOrder.setFmaijialy(buyerSaying);
                    newOrder.setFlianjidh(buyer.getFshoujih());
                    newOrder.setFyonghu(sys_XCredentialUserId);
                    newOrder.setFshangpinid(shangpin.getFid());
                    newOrder.setFxiadansj(com.justep.util.DateTimeUtil.now());
                    newOrder.setFmaijiaid(shangpin.getFmaijiaid());
                    newOrder.setFdingdanh(com.justep.util.RandomUtil.randomNumber(8));
                    newOrder.setFshouhuor(buyer.getFxingming());
                    newOrder.setFdingdanzt("待支付");
                    if (!(buyer.getFxinyongf() <= -30)) {
                        Dingdan currentOrder = com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.DingdanRepository.class).saveAndFlush(newOrder);
                        shangpin.setFkucun(0);
                        com.justep.cloud.boot.service.X5ContextService.getInstance(main.repository.Shangpin1Repository.class).saveAndFlush(shangpin);
                        return currentOrder.getFid();
                    } else {
                        return "信用过低";
                    }
                } else {
                    return "补充信息";
                }
            } else {
                return "补充信息";
            }
        }

    }
//系统生成代码,请不要修改或删除 <actionEnd:chuangjiandd>



	





	





	





	





	





	





	





	

}